package com.dbz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbz.entity.Journal;
import com.dbz.service.JournalService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/journal/")
@RestController
public class JournalController {
    @Resource
    private JournalService journalService;

    @RequestMapping("selectPage")
    public Map pageList(String uname, Integer page, Integer rows) {
        Map<String, Object> map = new HashMap<>();
        QueryWrapper<Journal> queryWrapper = new QueryWrapper<Journal>();
        queryWrapper.like(uname != "" && uname != null, "uname", uname);
        IPage<Journal> pages = new Page<Journal>(page, rows);
        map.put("rows", journalService.selectPage(pages, queryWrapper).getRecords());
        map.put("total", journalService.selectPage(pages, queryWrapper).getTotal());
        return map;
    }

    /**
     * 删除信息
     *
     * @param jid
     * @return
     */
    @RequestMapping("deleteJournal")
    public int deleteJournal(String jid) {
        return journalService.delecteJournal(jid);
    }
}
